/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.

 * /etc/mysql/my.cnf
 * bind-address = 192.168.0.140
 
 * @ phpmyadmin, Tab: Rechte
 * User erstellen: playbox/playbox
 * Host: jeder Host !
 */

package TestUmgebung;

import com.mysql.jdbc.Statement;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.naming.spi.DirStateFactory.Result;

/**
 *
 * @author Philipp
 */

public class dbConnectionTest {
        static String userid="playbox";
        static String password = "playbox";
	static String url = "jdbc:mysql://192.168.0.140:3306/playboxdb";

	static Connection con = null;

	public static void main(String[] args) throws Exception {
	    con = getOracleJDBCConnection();
	    java.sql.Statement stmt = null;
            ResultSet rs = null;

            if(con!= null){
	       System.out.println("Got Connection.");
	       DatabaseMetaData meta = con.getMetaData();
	       System.out.println("Driver Name : "+meta.getDriverName());
	       System.out.println("Driver Version : "+meta.getDriverVersion());

               stmt = con.createStatement();

               rs=stmt.executeQuery("Select * from usertab");
               while (rs.next()){
                   System.out.println("output@1:" + rs.getString(1));
                   System.out.println("output@2:" + rs.getString(2));
                   System.out.println("output@3:" + rs.getString(3));
                  // System.out.println("output@4:" + rs.getString(4));
               }

	    }else{
		    System.out.println("Could not Get Connection");
	    }
	}

	public static Connection getOracleJDBCConnection(){

		try {
			Class.forName("com.mysql.jdbc.Driver");

		} catch(java.lang.ClassNotFoundException e) {
			System.err.print("ClassNotFoundException:" );
			System.err.println(e.getMessage());
		}

		try {
		   con = DriverManager.getConnection(url, userid, password);
		} catch(SQLException ex) {
			System.err.println("SQLException: " + ex.getMessage());
		}

		return con;
	}

}
